package com.starblink.imgsearch.widget

import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.View
import androidx.annotation.ColorInt
import androidx.constraintlayout.widget.ConstraintLayout
import com.blankj.utilcode.util.BarUtils
import com.starblink.android.basic.ext.dp
import com.starblink.basic.util.CommUtils
import com.starblink.basic.util.ScreenUtils
import com.starblink.basic.util.log.YYLogUtils
import com.zhpan.indicator.option.AttrsController.initAttrs

class HollowImgScanLayout : View {
    private var mPaint: Paint? = null
    private var path: Path? = null
    private val w = ScreenUtils.getScreenWidth2()
    private val h = ScreenUtils.getScreenHeight()
    private var mAnchorRect: RectF? = null
    private var allRadius: Float = 32.dp.toFloat()
    private var outRect: RectF? = null

    constructor(context: Context) : this(context, null)
    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
        initPaint()
    }

    private fun initPaint() {
        mPaint = Paint()
        path = Path()
        //抗锯齿
        mPaint!!.isAntiAlias = true
        //防抖动
        mPaint!!.isDither = true
        mPaint!!.color = Color.parseColor("#000000")

        mAnchorRect = RectF(
            0f,
            44.dp.toFloat(),
            w.toFloat(),
            h.toFloat() - 57.dp- CommUtils.getBottomStatusHeight()
        )
        outRect = RectF(0f, 0f, w.toFloat(), h.toFloat())
    }

    override fun draw(canvas: Canvas?) {
        super.draw(canvas)
        path!!.fillType = Path.FillType.EVEN_ODD
        path!!.addRect(outRect!!, Path.Direction.CW)
        path!!.addRoundRect(mAnchorRect!!, allRadius, allRadius, Path.Direction.CW)
        canvas!!.drawPath(path!!, mPaint!!)
    }
}
